﻿using System.Net;

namespace Heimdallr.Net
{
    /// <summary>
    /// Provide a set of extenstion methods of <see cref="HttpModule"/>, <see cref="IHttpRequestModule"/> and <see cref="IHttpResponseModule"/>.
    /// </summary>
    public static class HttpModuleExtensions
    {
        internal static AuthenticationSchemes ToSchemes(this HttpModuleCredentialType credentialType)
        {
            switch (credentialType)
            {
                case HttpModuleCredentialType.None:
                    return AuthenticationSchemes.Anonymous;

                case HttpModuleCredentialType.Basic:
                    return AuthenticationSchemes.Basic;

                case HttpModuleCredentialType.Digest:
                    return AuthenticationSchemes.Digest;

                case HttpModuleCredentialType.Ntlm:
                    return AuthenticationSchemes.Ntlm;

                case HttpModuleCredentialType.Windows:
                    return AuthenticationSchemes.IntegratedWindowsAuthentication;

                default:
                    return AuthenticationSchemes.None;
            }
        }

        /// <summary>
        /// Returns the input as a request module.
        /// </summary>
        /// <param name="module">An <see cref="HttpModule"/> instance.</param>
        /// <returns>The conversion result.</returns>
        public static IHttpRequestModule AsRequest(this HttpModule module)
        {
            return module as IHttpRequestModule;
        }

        /// <summary>
        /// Returns the input as a response module.
        /// </summary>
        /// <param name="module">An <see cref="HttpModule"/> instance.</param>
        /// <returns>The conversion result.</returns>
        public static IHttpResponseModule AsResponse(this HttpModule module)
        {
            return module as IHttpResponseModule;
        }
    }
}